import { getEntireDepartments, getEntireRoles, getMenuData } from '@/service/main/main'
import type { IDepartmentList, IRoleList } from '@/types/main.ts/main'
import { defineStore } from 'pinia'

const useMainStore = defineStore('main', {
  state: () => ({
    roleList: [] as IRoleList[],
    departmentList: [] as IDepartmentList[],
    menuList: []
  }),
  actions: {
    // 获取角色数据
    async getEntireRolesAction() {
      const roleListRes = await getEntireRoles()
      this.roleList = roleListRes.data.list
    },
    // 获取部门数据
    async getEntireDepartmentsAction() {
      const departmentListRes = await getEntireDepartments()
      this.departmentList = departmentListRes.data.list
    },
    // 获取菜单数据
    async getMenuListAction() {
      const menuListRes = await getMenuData()
      this.menuList = menuListRes.data.list
    }
  }
})

export default useMainStore
